import { cache, cacheUrl } from '@/utils/cache'
import qs from 'qs'
const getItem = async item => {
	const res = await cache.getItem(item)
	return res
}
const getCacheUrl = async url => {
	const res = await cacheUrl.getItem(url)
	return res
}
const setCacheUrl = async (key, val) => {
	const res = await cacheUrl.setItem(key, val)
	return res
}
const removeCacheUrl = async item => {
	const res = await cacheUrl.removeItem(item)
	return res
}
const iterateCacheUrl = async () => {
	const arr = []
	await cacheUrl.iterate((value, key) => {
		arr.push({ cacheUrl: key })
	})
	return arr
}
const clearCacheUrl = () => {
	return cacheUrl.clear()
}
const setItem = async (key, val) => {
	const res = await cache.setItem(key, val)
	return res
}

const removeItem = async item => {
	const res = await cache.removeItem(item)
	return res
}
const iterate = async () => {
	const res = await cache.iterate()
	return res
}
const getReqKey = config => {
	const { method, url, params, data } = config
	return [method, url, qs.stringify(params), qs.stringify(data)].join('&')
}
export {
	getItem,
	setItem,
	removeItem,
	iterate,
	getReqKey,
	getCacheUrl,
	setCacheUrl,
	removeCacheUrl,
	iterateCacheUrl,
	clearCacheUrl,
}
